package edu.mse.camel.client.chat.handler;

import edu.mse.camel.client.chat.message.Message;
import edu.mse.camel.client.chat.message.MessageList;
import edu.mse.camel.client.eventbus.pubsub.ISubscriber;
import edu.mse.camel.client.events.EventIDs;
import edu.mse.camel.client.events.IEvent;
import edu.mse.camel.client.events.peer.*;
/*
 * This event handler is to handle the situation when the user receives 
 * the message from others. 
 * 
 * The event handler should be able to parse the content and the sender 
 * information from the event, and paint the related color on the message
 * based on the color information in ParticipantList. The message is appended
 * on the MessageList, and the display view is updated.
 * 
 */
public class ReceiveMessageEventHandler implements ISubscriber{

//	private final String handlerName = "Receive Message Handler";
	
	@Override
	public void notifyEvent(IEvent e) {
		if (e.getEventID().equalsIgnoreCase(EventIDs.RECEIVE_CHAT_EVENT)){

			ReceiveChatEvent rmEvent = (ReceiveChatEvent) e;
			
			Message message = new Message(rmEvent.getContent(), rmEvent.getName(), rmEvent.getOrginalTime());
			MessageList.getInstance().addMessage(message);
			
		}
		
	}

}
